const wx2my = require('../../../wx2my');
const Behavior = require('../../../Behavior');
var base = require('./../../../config.js');
var _Page;

function _defineProperty(e, t, a) {
  return t in e ? Object.defineProperty(e, t, {
    value: a,
    enumerable: !0,
    configurable: !0,
    writable: !0
  }) : e[t] = a, e;
}

var app = getApp(),
  siteinfo = require("../../../siteinfo.js"),
  imgArray1 = [];

Page((_defineProperty(_Page = {
  data: {
    length: 0,
    star: 0,
    starMap: ['非常差', '差', '一般', '好', '非常好'],
    imgUrl: wx2my.getStorageSync(["imgUrl1"]).data,
    imgArray1: []
  },

  // 评价几颗星
  myStarChoose(e) {
    let star = parseInt(e.currentTarget.dataset.star) || 0;
    this.setData({
      star: star
    }); // console.log(star);
  },

  onLoad: function(e) {
    var t = this;
    console.log(e);
    wx2my.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: '#ffffff'
    });
    t.setData({
      seller_id: e.seller_id,
      order_id: e.order_id,
      order_sn: e.order_sn
    })

    app.getUserInfo(function(e) {
      console.log(e),
        t.setData({
          user_id: e.id,
          imgUrl: wx2my.getStorageSync(["imgUrl1"]).data
        });
    });
  },

  textarea: function(e) {
    console.log(e);
    var t = e.detail.cursor;
    "" != e.detail.value && this.setData({
      length: t,
      value: e.detail.value
    });
  },

  submit: function(e) {
    this.data.value;
  },

  img_array: function(e) {
    console.log(e.success);
    var i = e.success ? e.success : 0;
    console.log('上传9张图片')
    var a = this;
    if (9 <= imgArray1.length) console.log('最多....'), my.alert({
      title: '温馨提示',
      content: '最多提交9张图片',
      buttonText: '我知道了',
    });
    else {
      console.log('最少....')
      var t = 9 - imgArray1.length;
      var basement = siteinfo.siteroot + "?i=" + siteinfo.uniacid + "&c=entry&a=wxapp&do=Upload&m=zh_jdgjb";
      console.log(basement)
      my.chooseImage({
        count: 9,
        success: res => {
          
          console.log(res)
          const path = res.apFilePaths;
          console.log(path)
          // var i = 0;
          path.forEach((item, index) => {
            my.uploadFile({
              url: siteinfo.siteroot + "?i=" + siteinfo.uniacid + "&c=entry&a=wxapp&do=Upload&m=zh_jdgjb",
              fileType: 'image',
              fileName: 'upfile',
              filePath: path[index],
              success: (e) => {
                console.log(e);
                // // var data = JSON.parse(res.data);
                // var data = res.data;
                // // console.log(data)
                // var item = data.data;
                // console.log('上传成功')
                // // i++,
                // "" != item ? ( imgArray1.push(item), 0 < imgArray1.length ? a.setData({
                //   imgArray1: imgArray1,
                //   edit: !0
                // }) : a.setData({
                //   edit: !1
                // }), console.log("上传商家轮播图时候提交的图片数组", imgArray1)) : wx2my.showToast({
                //   icon: "loading",
                //   title: "请重试"
                // });
                console.log(e);
                "" != e.data ? (i++ , imgArray1.push(e.data), 0 < imgArray1.length ? a.setData({
                  imgArray1: imgArray1,
                  edit: !0
                }) : a.setData({
                  edit: !1
                }), console.log("上传商家轮播图时候提交的图片数组", imgArray1)) : wx2my.showToast({
                  icon: "loading",
                  title: "请重试"
                });

              },
            });
          })
        },
      });

    }
  },
  // 之前的上传图片
  // uploadimg: function (e) {
  //   console.log(e);
  //   console.log(e.path)
  //   var t = this,
  //       a = e.i ? e.i : 0,
  //       i = e.success ? e.success : 0,
  //       o = e.fail ? e.fail : 0;
  //   my.uploadFile({
  //     url: e.url,
  //     fileType: 'image',
  //     filePath: e.path,
  //     fileName: "upfile",
  //     success: (e) => {
  //       console.log('上传文件成功。。。。。')
  //       console.log(e);
  //       "" != e.data ? (i++, imgArray1.push(e.data), 0 < imgArray1.length ? t.setData({
  //         imgArray1: imgArray1,
  //         edit: !0
  //       }) : t.setData({
  //         edit: !1
  //       }), console.log("上传商家轮播图时候提交的图片数组", imgArray1)) : wx2my.showToast({
  //         icon: "loading",
  //         title: "请重试"
  //       });
  //     },
  //     fail: (e) => {
  //       console.log('上传失败')
  //       console.log(e)
  //       o++;
  //     },
  //     complete: function () {
  //       console.log('上传两者')
  //       // ++a == e.path.length ? (t.setData({
  //       //   images: e.path
  //       // }), wx2my.hideToast()) : (e.i = a, e.success = i, e.fail = o, t.uploadimg(e));
  //     }
  //   });
  // },
  delete: function(e) {
    console.log('here')
    console.log(e);
    var t = e.currentTarget.dataset.index;
    Array.prototype.indexOf = function(e) {
      for (var t = 0; t < this.length; t++) if (this[t] == e) return t;

      return -1;
    }, Array.prototype.remove = function(e) {
      var t = this.indexOf(e);
      -1 < t && this.splice(t, 1);
    }, imgArray1.remove(imgArray1[t]), this.setData({
      imgArray1: imgArray1
    });
  }
}, "submit", function(e) {
  console.log('where')
  var arr = [];
  imgArray1.forEach((item) => {
    arr.push(item);
  })
  console.log(imgArray1)
  var t = this,
    a = arr.join(","),
    i = t.data.value,
    o = wx2my.getStorageSync(["userInfo"]).data.uid,//t.data.user_id,
    r = 115, // t.data.seller_id,
    n = '201905221642093745';  //t.data.order_id;
  console.log(a)
  console.log(i)
  console.log(o)
  console.log(r)
  console.log(n)
  wx2my.newRequest({
    url: base.siteroot,
    data: {
      c: 'entry',
      a: 'wxapp',
      do: 'SaveAssess',
      m: 'zh_jdgjb',
      user_id: o,
      img: a,
      content: i,
      order_id: n,
      seller_id: r,
      star: t.data.star,
      order_sn: '201905221642093745'// t.data.order_sn
    },
    success: (res) => {
      my.alert({
        title: '提交成功'
      });
      setTimeout(function() {
        my.navigateBack({
          delta: 2
        });
      }, 1500)
      console.log('提交成功')
      console.log(res)
    },
    fail: (err) => {
      console.log(err)
    }
  })

  // app.util.request({
  //   url: "entry/wxapp/SaveAssess",
  //   data: {
  //     user_id: o,
  //     img: a,
  //     content: i,
  //     order_id: n,
  //     seller_id: r,
  //     star: t.data.star,
  //     order_sn: t.data.order_sn
  //   },
  //   success: function (e) {
  //     console.log(e), 1 == e.data ? (wx2my.showToast({
  //       title: "提交成功"
  //     }), setTimeout(function () {
  //       wx2my.navigateBack({
  //         delta: 2
  //       });
  //     }, 1500)) : wx2my.showModal({
  //       title: "",
  //       content: "系统出差了，待会再试一下"
  //     });
  //   }
  // });

}),
  _defineProperty(_Page, "onReady", function() { }), _defineProperty(_Page, "onShow", function() { }), _defineProperty(_Page, "onHide", function() { }), _defineProperty(_Page, "onUnload", function() {
    this.setData({
      imgArray1: []
    });
  }), _defineProperty(_Page, "onPullDownRefresh", function() { }), _defineProperty(_Page, "onReachBottom", function() { }), _defineProperty(_Page, "onShareAppMessage", function() { }), _Page));